#pragma GCC optimize(2, "Ofast", "inline")
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <algorithm>
#define endl '\n'
#define int long long
#define pii pair<int, int>
using namespace std;

// 已知
int n, l;
vector<int>a;
// 未知

int ans = 0;



void input()
{
    cin >> n >> l;
    if (l % 3 != 0)
    {
        cout << 0;
        exit(0);
    }
    a.resize(n);
    for (int i = 0;i < n - 1;++i)
    {
        cin >> a[i];
    }
}

void solve()
{
    vector<int>pos(n);
    unordered_map<int, int>mp;
    pos[0] = 0; // 0号点在0号
    mp[0] = 1; // 0号点出现一次
    for (int i = 1;i < n;++i)
    {
        pos[i] = (pos[i - 1] + a[i - 1]) % l;
        mp[pos[i]]++;
    }
    for (int i = 0;i < n;++i)
    {
        //找到其他的点
        int p2 = (pos[i] + l / 3) % l;
        int p3 = (pos[i] + l * 2 / 3) % l;
        if (mp[p2] && mp[p3])
        {
            ans += mp[p2] * mp[p3];
        }
    }
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    input();
    solve();
    cout << ans / 3 << endl;
    return 0;
}